package be.jabapage.snooker.service.importation.impl;

import java.io.Serializable;
import java.util.logging.Logger;

import org.apache.commons.lang.Validate;
import org.apache.poi.ss.usermodel.Workbook;

import be.jabapage.snooker.container.RegionClubContainer;
import be.jabapage.snooker.jdo.administration.Region;
import be.jabapage.snooker.service.importation.api.IExcelClubParser;
import be.jabapage.snooker.service.importation.api.IExcelImportService;

/**
 * @author axesq
 *
 */
public class ExcelImportService implements IExcelImportService, Serializable {

	private static final long serialVersionUID = -5531487213828606495L;

	private final IExcelClubParser clubParser;

	/**
	 * @param clubParser
	 */
	public ExcelImportService(final IExcelClubParser clubParser) {
		Validate.notNull(clubParser);
		this.clubParser = clubParser;

	}
	private static final Logger LOGGER = Logger.getLogger(ExcelImportService.class.getName());

	/**
	 * {@inheritDoc}
	 */
	public RegionClubContainer importExcel(final Workbook workBook) {
		LOGGER.info("Start importing.");
		Validate.notNull(workBook);
		RegionClubContainer regionContainer = new RegionClubContainer();
		regionContainer.setRegion(parseRegion(workBook));
		regionContainer.setClubs(clubParser.parse(workBook));
		return regionContainer;
	}

	private Region parseRegion(final Workbook workBook) {
		Validate.notNull(workBook);
		Region region = new Region();
		region.setName("Oost-Vlaanderen");
		return region;
	}
}